<?php

include_once 'Answer_Patterns.php';
include_once 'Mount_DOM_tree.php';

class Refactoring_Flash extends Answer_Patterns {

   public function start($domDocument) {
      $result = "";

      $search = $domDocument->getElementsByTagName('object');
      
      foreach ($search as $f) {
       
         if (ereg("^(.*).swf$", strtolower($f->getElementsByTagName('embed')->item(0)->getAttribute('src')))) {
            $answer = '&LT;video width="' . $f->getAttribute('width') . '" height="' . $f->getAttribute('height') . '"'
                    . 'src="' . $f->getElementsByTagName('embed')->item(0)->getAttribute('src') . '" '
                    . '/&GT;';
            
            $mount_tree = new Mount_DOM_tree();
            $result .= parent::elementAnswerPatterns("&LT;object&GT;", $f->getLineNo(), "&LT;video/&GT;");
            $result .= parent::tableAnswer($mount_tree->structHTML($f, 1, 0), $answer);
         }
      }

      if (!empty($result)) {
         $result = parent::titleAnswerPatterns("Integrar vídeos em Flash para HTML 5") . $result;
      }

      return $result;
   }

}

?>